<?php
error_reporting ( 0 );
include_once "cache.php";

/** 
 * Return current API URL 
 */
function api_get_url() {
	return "http://latex.codecogs.com";
}
?>
<?

$url = api_get_url ();

if (isset ( $_REQUEST ["pictype"] )) {
	$catalog = $_REQUEST ["pictype"];
} else {
	$catalog = 'gif';
}
$url = $url . '/' . $catalog . '.latex';

header ( "Content-type: image/" . $catalog );

if (isset ( $_REQUEST ["latex"] )) {
	$latex = $_REQUEST ["latex"];
} else {
	$latex = '\int_{-2}^{2}x^{2}+2x+1';
}
$url = $url . '?' . $latex;

/*
$filename = getCacheFilename ( $_REQUEST );
if ($fh = fopen ( $filename, "r" )) {
	// 有缓冲
	$content = getContent ( $filename );
	fclose ( $fh );
} else { // 没有缓冲 */
$ch = curl_init ( $url );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
$content = curl_exec ( $ch );
curl_close ( $ch );
/*
if ($fh = fopen ( $filename, "w" )) {
	fwrite ( $fh, $content );
	fclose ( $fh );
}
}
*/

echo $content;

?>
